import useStateIfMounted from "@/hooks/useStateIfMounted";
import React, { useEffect } from "react";

const UseMounted: React.FC = () => {
  const [count, setCount] = useStateIfMounted<number>(0);

  useEffect(() => {
    const timer = setTimeout(() => {
      setCount(prev => prev + 2);
    }, 2000);

    return () => {
      clearTimeout(timer);
    };
  }, [setCount]);

  return (
    <section>
      <h3>测试组件加载</h3>
      <p>计数：{count}</p>
    </section>
  );
};
export default UseMounted;
